/**
 * Created by Administrator on 2019/5/20/020.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"

class CZML_CommunicationLink {
  constructor(viewer, idTarget, idBasic, vOrbitStartTime, vOrbitEndTime) {
    this._viewer = viewer
    this.idTarget = idTarget
    this.idBasic = idBasic
    this.vOrbitStartTime = vOrbitStartTime
    this.vOrbitEndTime = vOrbitEndTime
    this.CZML_AddCommunicationLink()
  }

  CZML_AddCommunicationLink() {
    // 首先查找idTarget和idBasic是否都存在
    if (CZML_GENERALTOOLS_CLASS.CheckIDIsExit(this.idTarget) === false || CZML_GENERALTOOLS_CLASS.CheckIDIsExit(this.idBasic) === false) {
      return false
    }
    // 删除所有两者相关的通信节点
    CZML_GENERALTOOLS_CLASS.DeleteCesiumObjectsByMaskStr(this.idTarget + "-to-" + this.idBasic)
    // 添加引用
    const CurPos1 = this.idTarget + "#position"
    const CurPos2 = this.idBasic + "#position"
    const CurColor = this.idBasic + "#label.fillColor"
    // 通信数据
    for (let i = 0; i < this.vOrbitStartTime.length; i++) {
      const AvailabilityTime =
        CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.vOrbitStartTime[i]) +
        "/" +
        CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.vOrbitEndTime[i])
      const AccessData = {
        id: this.idTarget + "-to-" + this.idBasic + "-index" + (i + 1),
        availability: AvailabilityTime,
        polyline: {
          show: [
            {
              interval: AvailabilityTime,
              boolean: true
            }
          ],
          width: 2,
          material: {
            solidColor: {
              color: {
                reference: CurColor
              }
            }
          },
          followSurface: false,
          positions: {
            references: [CurPos1, CurPos2]
          }
        }
      }
      CZML_GENERALTOOLS_CLASS.CzmlList.push(AccessData)
    }
    /// /上图
    CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
    return true
  }
}

export default CZML_CommunicationLink
